package ucm;

import java.sql.*;
import model.UCModel;


public class UCDeleteUser extends UCModel{

    public UCDeleteUser(String text, String text0) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public boolean run() {
        if (DBconnect == null) {
            DBconnect = new DBConnect();
        }

        try {
            Statement stmt = DBconnect.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ResultSet rset = stmt.executeQuery("select * from user where name = '" + username + "'");
            if (!rset.first()) {
                System.out.println("USER DOES NOT EXIT");
                return false;
            }
            if (password.equals(rset.getString("password"))) {
                stmt.executeUpdate("delete from user where name = '" + username + "'");
                return true;
            } else {
                System.out.println("PASSWORD IS NOT CORRECT");
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }
}
